package com.siti.kindnessplatform.base.ctrl;

import com.alibaba.fastjson.JSON;
import com.siti.kindnessplatform.aspect.RequestLimit;
import com.siti.kindnessplatform.base.biz.HospitalBiz;
import com.siti.kindnessplatform.base.po.Hospital;
import com.siti.kindnessplatform.common.CommonResult;
import com.siti.kindnessplatform.util.AESUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("hospital")
public class HospitalCtrl {

	@Resource
    private HospitalBiz hospitalBiz;

    @RequestLimit(maxCount = 10)
    @GetMapping(value = "selectHospital")
    public CommonResult selectHospital(String content, Integer hour, Integer orgType) {
    	Map<String,Object> map = new HashMap<String,Object>();
        List<Hospital> list= hospitalBiz.selectHospital(content, hour,orgType);
        map.put("datas", list);
        String encrypt = "";
        try {
        	String json = URLEncoder.encode(JSON.toJSONString(map), "UTF-8");
        	String enjson = AESUtil.Encrypt(json);
			encrypt = enjson.replaceAll(System.lineSeparator(), "");//将换行符替换为空
			//System.out.println("de"+URLDecoder.decode(AESUtil.Decrypt(enjson), "UTF-8"));
			return new CommonResult("success","请求成功",encrypt);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new CommonResult("error","请求失败");
    }
    
    @GetMapping(value = "findTopCity")
    public List<String> findTopCity(Integer top,Integer orgType){
		return hospitalBiz.findTopCity(top,orgType);
	}
		
    @GetMapping(value = "findTopProvince")
	public List<String> findTopProvince(Integer top,Integer orgType){
		return hospitalBiz.findTopProvince(top,orgType);
	}
	
    @GetMapping(value = "findTopSupplies")
	public List<String> findTopSupplies(Integer top,Integer orgType){
		return hospitalBiz.findTopSupplies(top,orgType);
	}
}
